home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdevs3ga.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  7.3 KB  |  248 lines

  1. /* Copyright (C) 1992, 1996, 1997 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gdevs3ga.c,v 1.2 2000/09/19 19:00:22 lpd Exp $ */
  20. /* S3 86C911 driver */
  21. #include "gx.h"
  22. #include "gserrors.h"
  23. #include "gxdevice.h"
  24. #include "gdevpcfb.h"
  25. #include "gdevsvga.h"
  26.  
  27. /* Shared routines from gdevsvga.c */
  28. extern int vesa_get_mode(P0());
  29. extern void vesa_set_mode(P1(int));
  30.  
  31. /* Macro for casting gx_device argument */
  32. #define fb_dev ((gx_device_svga *)dev)
  33.  
  34. /* ------ The S3 86C911 device ------ */
  35.  
  36. private dev_proc_open_device(s3_open);
  37. private dev_proc_fill_rectangle(s3_fill_rectangle);
  38. private dev_proc_copy_mono(s3_copy_mono);
  39. private const gx_device_procs s3_procs =
  40. {
  41.     s3_open,
  42.     NULL,            /* get_initial_matrix */
  43.     NULL,            /* sync_output */
  44.     NULL,            /* output_page */
  45.     svga_close,
  46.     svga_map_rgb_color,
  47.     svga_map_color_rgb,
  48.     s3_fill_rectangle,
  49.     NULL,            /* tile_rectangle */
  50.     s3_copy_mono,
  51.     svga_copy_color,
  52. /****** DOESN'T WORK ******/
  53.     NULL,            /* draw_line */
  54.     svga_get_bits
  55. /****** DOESN'T WORK ******/
  56. };
  57. gx_device_svga far_data gs_s3vga_device =
  58. svga_device(s3_procs, "s3vga", vesa_get_mode, vesa_set_mode, NULL);
  59.  
  60. /* Keep track of the character bitmap cache in off-screen memory. */
  61. #define log2_cell_width 5
  62. #define cell_width (1 << log2_cell_width)
  63. #define cache_x_bits (log2_cache_width_bits - log2_cell_width)
  64. #define log2_cell_height 5
  65. #define cell_height (1 << log2_cell_height)
  66. #define cache_y_bits (log2_cache_height - log2_cell_height)
  67. #define log2_cache_width_bits 10
  68. #define log2_cache_width_bytes (log2_cache_width_bits - 3)
  69. #define log2_cache_height 8
  70. #define log2_cache_capacity (cache_x_bits + cache_y_bits)
  71. #define cache_capacity (1 << log2_cache_capacity)
  72. private gx_bitmap_id cache_ids[cache_capacity];
  73.  
  74. /* Define additional registers and I/O addresses. */
  75. #define crtc_addr 0x3d4        /* (color) */
  76. #define crt_lock 0x35
  77. #define crt_s3_lock1 0x38
  78. #define crt_s3_lock2 0x39
  79. #define s3_y_pos 0x82e8
  80. #define s3_x_pos 0x86e8
  81. #define s3_y_dest 0x8ae8
  82. #define s3_x_dest 0x8ee8
  83. #define s3_width 0x96e8
  84. #define s3_status 0x9ae8    /* read only */
  85. #define s3_command 0x9ae8    /* write only */
  86. #define s3_back_color 0xa2e8
  87. #define s3_fore_color 0xa6e8
  88. #define s3_write_mask 0xaae8
  89. #define s3_read_mask 0xaee8
  90. #define s3_back_mix 0xb6e8
  91. #define s3_fore_mix 0xbae8
  92. #define s3_height 0xbee8
  93. #define s3_mf_control 0xbee8
  94. #  define mf_data_ones 0xa000
  95. #  define mf_data_cpu 0xa080
  96. #  define mf_data_display 0xa0c0
  97. #define s3_pixel_data 0xe2e8
  98. /* Wait for the command FIFO to empty. */
  99. #define s3_wait_fifo()\
  100.   while ( inport(s3_status) & 0xff )
  101. /* Load the parameters for a rectangle operation. */
  102. #define out_s3_rect(x, y, w, h)\
  103.   (outport(s3_x_pos, x), outport(s3_y_pos, y),\
  104.    outport(s3_width, (w) - 1), outport(s3_height, (h) - 1))
  105.  
  106. private int
  107. s3_open(gx_device * dev)
  108. {
  109.     static const mode_info mode_table[] =
  110.     {
  111.     {640, 480, 0x201},
  112.     {800, 600, 0x203},
  113.     {1024, 768, 0x205},
  114.     {-1, -1, -1}
  115.     };
  116.     int code = svga_find_mode(dev, mode_table);
  117.  
  118.     if (code < 0)
  119.     return_error(gs_error_rangecheck);
  120.     /* The enhanced modes all use a 1024-pixel raster. */
  121.     fb_dev->raster = 1024;
  122.     code = svga_open(dev);
  123.     if (code < 0)
  124.     return code;
  125.     /* Clear the cache */
  126.     {
  127.     int i;
  128.  
  129.     for (i = 0; i < cache_capacity; i++)
  130.         cache_ids[i] = gx_no_bitmap_id;
  131.     }
  132.     return 0;
  133. }
  134.  
  135. /* Fill a rectangle. */
  136. int
  137. s3_fill_rectangle(gx_device * dev, int x, int y, int w, int h,
  138.           gx_color_index color)
  139. {
  140.     fit_fill(dev, x, y, w, h);
  141.     s3_wait_fifo();
  142.     outport(s3_fore_mix, 0x27);
  143.     outport(s3_fore_color, (int)color);
  144.     outport(s3_mf_control, mf_data_ones);
  145.     out_s3_rect(x, y, w, h);
  146.     outport(s3_command, 0x40b3);
  147.     return 0;
  148. }
  149.  
  150. /* Copy a monochrome bitmap.  The colors are given explicitly. */
  151. /* Color = gx_no_color_index means transparent (no effect on the image). */
  152. private int
  153. s3_copy_mono(gx_device * dev,
  154.          const byte * base, int sourcex, int raster, gx_bitmap_id id,
  155.       int x, int y, int w, int h, gx_color_index czero, gx_color_index cone)
  156. {
  157.     int sbit;
  158.     const byte *sptr;
  159.     int run;
  160.     byte lmask;
  161.     byte lmerge = 0;
  162.     int cache_index, cache_x, cache_y;
  163.     int i, j;
  164.  
  165.     fit_copy(dev, base, sourcex, raster, id, x, y, w, h);
  166.     sbit = sourcex & 7;
  167.     sptr = base + (sourcex >> 3);
  168.     run = (sbit + w + 7) >> 3;
  169.     lmask = 0xff >> sbit;
  170.     /* See whether the cache is applicable. */
  171.     if (id != gx_no_bitmap_id && w <= cell_width - 7 &&
  172.     h <= cell_height
  173.     ) {
  174.     cache_index = (int)(id & (cache_capacity - 1));
  175.     cache_x = ((cache_index & ((1 << cache_x_bits) - 1)) <<
  176.            log2_cell_width) + 7;
  177.     cache_y = ((cache_index >> cache_x_bits) <<
  178.            log2_cell_height) + 768;
  179.     if (cache_ids[cache_index] != id) {
  180.         cache_ids[cache_index] = id;
  181.         /* Copy the bitmap to the cache. */
  182.         s3_wait_fifo();
  183.         out_s3_rect(cache_x - sbit, cache_y, w + sbit, h);
  184.         outport(s3_fore_mix, 0x22);        /* 1s */
  185.         outport(s3_back_mix, 0x01);        /* 0s */
  186.         outport(s3_mf_control, mf_data_cpu);
  187.         outport(s3_command, 0x41b3);
  188.         {
  189.         const int skip = raster - run;
  190.  
  191.         for (i = h; i > 0; i--, sptr += skip)
  192.             for (j = run; j > 0; j--, sptr++)
  193.             outportb(s3_pixel_data, *sptr);
  194.         }
  195.     }
  196.     s3_wait_fifo();
  197.     } else {
  198.     cache_index = -1;
  199.     if (lmask != 0xff) {    /* The hardware won't do the masking for us. */
  200.         if (czero != gx_no_color_index) {
  201.         if (cone != gx_no_color_index) {
  202.             s3_fill_rectangle(dev, x, y, w, h, czero);
  203.             czero = gx_no_color_index;
  204.         } else {
  205.             lmerge = ~lmask;
  206.         }
  207.         }
  208.     }
  209.     s3_wait_fifo();
  210.     out_s3_rect(x - sbit, y, w + sbit, h);
  211.     }
  212.     /* Load the colors for the real transfer. */
  213.     if (cone != gx_no_color_index) {
  214.     outport(s3_fore_mix, 0x27);
  215.     outport(s3_fore_color, (int)cone);
  216.     } else
  217.     outport(s3_fore_mix, 0x63);
  218.     if (czero != gx_no_color_index) {
  219.     outport(s3_back_mix, 0x07);
  220.     outport(s3_back_color, (int)czero);
  221.     } else
  222.     outport(s3_back_mix, 0x63);
  223.     s3_wait_fifo();
  224.     if (cache_index < 0) {    /* direct transfer */
  225.     outport(s3_mf_control, mf_data_cpu);
  226.     outport(s3_command, 0x41b3);
  227.     if (run == 1 && !lmerge) {    /* special case for chars */
  228.         for (i = h; i > 0; i--, sptr += raster)
  229.         outportb(s3_pixel_data, *sptr & lmask);
  230.     } else {
  231.         const int skip = raster - run;
  232.  
  233.         for (i = h; i > 0; i--, sptr += skip) {
  234.         outportb(s3_pixel_data, (*sptr++ & lmask) | lmerge);
  235.         for (j = run; j > 1; j--, sptr++)
  236.             outportb(s3_pixel_data, *sptr);
  237.         }
  238.     }
  239.     } else {            /* Copy the character from the cache to the screen. */
  240.     out_s3_rect(cache_x, cache_y, w, h);
  241.     outport(s3_x_dest, x);
  242.     outport(s3_y_dest, y);
  243.     outport(s3_mf_control, mf_data_display);
  244.     outport(s3_command, 0xc0b3);
  245.     }
  246.     return 0;
  247. }
  248.